package Year22_Month03.day21;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
           String str = sc.nextLine();
           while(str.length() > 1){
               int res = 0;
               for (int i = 0; i < str.length(); i++) {
                   res += str.charAt(i) - '0';
               }
               str = String.valueOf(res);
           }
           System.out.println(str);
        }
    }
}
